package com.asiainfo.ssm.execute.dao.impl;

import java.rmi.RemoteException;
import java.util.HashMap;

import com.asiainfo.ssm.execute.bo.BOExecTodoOrderEngine;
import com.asiainfo.ssm.execute.dao.interfaces.IExecTodoOrderDAO;
import com.asiainfo.ssm.execute.ivalues.IBOExecTodoOrderValue;

public class ExecTodoOrderDAOImpl implements IExecTodoOrderDAO {

	@Override
	public void saveExecTodoOrder(IBOExecTodoOrderValue[] values) throws Exception, RemoteException {
		for (IBOExecTodoOrderValue value : values) { 
        	if (value.isNew())
    		{
    			long newId = BOExecTodoOrderEngine.getNewId().longValue();
    			value.setOrdId(newId); 
    		} 
        }
		BOExecTodoOrderEngine.saveBatch(values);
	}

	@Override
	public void deleteExecTodoOrder(IBOExecTodoOrderValue[] values) throws Exception {
		for (IBOExecTodoOrderValue value : values) { 
			value.delete();
		}

		BOExecTodoOrderEngine.saveBatch(values);
	}

	@Override
	public IBOExecTodoOrderValue[] getExecTodoOrder(int mod , int modValue, int rowNum) throws Exception, RemoteException {
		String sql = "where mod(ORD_ID,:mod) = :modValue and rownum = :rowNum order by resp_id";
		HashMap parameters =  new HashMap<>();
		parameters.put("rowNum", rowNum);
		parameters.put("modValue", modValue);
		parameters.put("mod", mod);

		IBOExecTodoOrderValue[] list = BOExecTodoOrderEngine.getBeans(sql,parameters);
		return list;
	}

}
